package com.mysql.Servlet;

import com.mysql.dao.J2ee_testDAO;
import com.mysql.dao.impl.J2ee_testDAOImpl;
import com.mysql.entity.J2ee_test;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import static com.mysql.DB.DBUtils.getConnection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServletJ2ee extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("doget");
        int k=0;
        if (req.getParameter("text")!=null)
            k =Integer.parseInt(req.getParameter("text").toString());
        System.out.println(k);
        Connection conn= null;
        try {
            conn = getConnection();
            List<J2ee_test> j2ee_testList= new ArrayList<J2ee_test>();
            J2ee_testDAO j2ee_testDAO1=new J2ee_testDAOImpl();

            BufferedReader reader=new BufferedReader(new FileReader("D:\\学校用文档\\大数据展示\\src\\ID.txt"));
            String line=null;
            List list=new ArrayList();
            while ((line=reader.readLine())!=null){
                list.add(line);
            }
            if(k==0) k=1;
            System.out.println(list.get(10));
            for (int i=0;i<10;i++,k++){
                J2ee_test j2ee_test1 = j2ee_testDAO1.Select(conn, Integer.parseInt(list.get(k+1).toString()) );
                System.out.println(j2ee_test1.toString());
                j2ee_testList.add(j2ee_test1);
            }
            req.setAttribute("video",j2ee_testList);
            req.getRequestDispatcher("index.jsp").forward(req,resp);
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
